package com.example.pkmedical.Activity.rollovershock;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextClock;
import android.widget.TextView;

import androidx.fragment.app.FragmentTransaction;


import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.Fragments.rollover.RolloverCustomizedFragment;
import com.example.pkmedical.Fragments.rollover.RolloverHighFragment;
import com.example.pkmedical.Fragments.rollover.RolloverLowFragment;
import com.example.pkmedical.Fragments.rollover.RolloverSecondaryFragment;
import com.example.pkmedical.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RolloverActivity extends BaseActivity {

    @BindView(R.id.main_house)
    ImageView mainHouse;
    @BindView(R.id.top_icon_layout)
    RelativeLayout topIconLayout;
    @BindView(R.id.main_house_text)
    TextView mainHouseText;
    @BindView(R.id.main_date)
    TextClock mainDate;
    @BindView(R.id.rollover_high)
    TextView rolloverHigh;
    @BindView(R.id.rollover_secondary)
    TextView rolloverSecondary;
    @BindView(R.id.rollover_low)
    TextView rolloverLow;
    @BindView(R.id.rollover_customized)
    TextView rolloverCustomized;
    @BindView(R.id.rollover_framelayout)
    FrameLayout rolloverFramelayout;
    RolloverHighFragment rolloverHighFragment;
    RolloverSecondaryFragment rolloverSecondaryFragment;
    RolloverLowFragment rolloverLowFragment;
    RolloverCustomizedFragment rolloverCustomizedFragment;
    @BindView(R.id.rollover_bottom_goback)
    TextView rolloverBottomGoback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rollover_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        mainHouse.setImageResource(R.drawable.img_title_fbzl);
        mainHouseText.setText(R.string.fbzl_cefan);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        hideAllFragment(transaction);
        high_on();
        if (rolloverHighFragment == null) {
            rolloverHighFragment = new RolloverHighFragment();
            transaction.add(R.id.rollover_framelayout, rolloverHighFragment);
        } else {
            transaction.show(rolloverHighFragment);
        }
        transaction.commit();
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }


    @OnClick({R.id.rollover_high, R.id.rollover_secondary, R.id.rollover_low, R.id.rollover_customized, R.id.rollover_bottom_goback})
    public void onViewClicked(View view) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        hideAllFragment(transaction);
        switch (view.getId()) {
            case R.id.rollover_high:
                high_on();
                if (rolloverHighFragment == null) {
                    rolloverHighFragment = new RolloverHighFragment();
                    transaction.add(R.id.rollover_framelayout, rolloverHighFragment);
                } else {
                    transaction.show(rolloverHighFragment);
                }
                break;
            case R.id.rollover_secondary:
                secondary_on();
                if (rolloverSecondaryFragment == null) {
                    rolloverSecondaryFragment = new RolloverSecondaryFragment();
                    transaction.add(R.id.rollover_framelayout, rolloverSecondaryFragment);
                } else {
                    transaction.show(rolloverSecondaryFragment);
                }
                break;
            case R.id.rollover_low:
                low_on();
                if (rolloverLowFragment == null) {
                    rolloverLowFragment = new RolloverLowFragment();
                    transaction.add(R.id.rollover_framelayout, rolloverLowFragment);
                } else {
                    transaction.show(rolloverLowFragment);
                }
                break;
            case R.id.rollover_customized:
                customized_on();
                if (rolloverCustomizedFragment == null) {
                    rolloverCustomizedFragment = new RolloverCustomizedFragment();
                    transaction.add(R.id.rollover_framelayout, rolloverCustomizedFragment);
                } else {
                    transaction.show(rolloverCustomizedFragment);
                }
                break;
            case R.id.rollover_bottom_goback:
                finish();
//                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                break;
        }
        transaction.commit();
    }

    private void high_on() {
        rolloverHigh.setBackgroundResource(R.drawable.changgui_item_back_on);
        rolloverHigh.setTextColor(getResources().getColor(R.color.green_back_text));
        rolloverSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverSecondary.setTextColor(getResources().getColor(R.color.white));
        rolloverLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverLow.setTextColor(getResources().getColor(R.color.white));
        rolloverCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void secondary_on() {


        rolloverHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverHigh.setTextColor(getResources().getColor(R.color.white));
        rolloverSecondary.setBackgroundResource(R.drawable.changgui_item_back_on);
        rolloverSecondary.setTextColor(getResources().getColor(R.color.green_back_text));
        rolloverLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverLow.setTextColor(getResources().getColor(R.color.white));
        rolloverCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void low_on() {
        rolloverHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverHigh.setTextColor(getResources().getColor(R.color.white));
        rolloverSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverSecondary.setTextColor(getResources().getColor(R.color.white));
        rolloverLow.setBackgroundResource(R.drawable.changgui_item_back_on);
        rolloverLow.setTextColor(getResources().getColor(R.color.green_back_text));
        rolloverCustomized.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverCustomized.setTextColor(getResources().getColor(R.color.white));
    }

    private void customized_on() {
        rolloverHigh.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverHigh.setTextColor(getResources().getColor(R.color.white));
        rolloverSecondary.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverSecondary.setTextColor(getResources().getColor(R.color.white));
        rolloverLow.setBackgroundResource(R.drawable.changgui_item_back_off);
        rolloverLow.setTextColor(getResources().getColor(R.color.white));
        rolloverCustomized.setBackgroundResource(R.drawable.changgui_item_back_on);
        rolloverCustomized.setTextColor(getResources().getColor(R.color.green_back_text));
    }

    public void hideAllFragment(FragmentTransaction transaction) {
        if (rolloverHighFragment != null) {
            transaction.hide(rolloverHighFragment);
        }
        if (rolloverSecondaryFragment != null) {
            transaction.hide(rolloverSecondaryFragment);
        }
        if (rolloverLowFragment != null) {
            transaction.hide(rolloverLowFragment);
        }
        if (rolloverCustomizedFragment != null) {
            transaction.hide(rolloverCustomizedFragment);
        }
    }
}
